/*
 * Log4Test.java
 *
 * Created on October 21, 2002, 11:49 AM
 */

package test;

import org.apache.log4j.*;
import java.io.*;
import java.util.*;
import java.net.*;


/**
 *
 * @author  llaranje
 * @version 
 */
public class Log4Test1 {
   private static final Category trace = Category.getInstance( Log4Test.class );
   private static final String PROPERTIES_FILE = "log4test.properties";
   private static final String TRACE_FILE = "test";
   private static String redmandir = ".";

   //--------------------------------------------------------------------------

   /**
    * Static initializer. Initialization function is performed here to ensure
    * log4j is initialized before any other callMain functions are called.
    */
   static
   {
      if (Test.rmcfgfiledir != null) redmandir = Test.rmcfgfiledir;
      //
      // Load the configuration properties
      //
      File propFile = new File( redmandir, PROPERTIES_FILE );
      Properties props = new Properties();
      FileInputStream is = null;
      
      //System.out.println( "Log4JService: Using properties file '" + redmandir + "/" + PROPERTIES_FILE 
      //                          + "', and trace file 'logs/" + TRACE_FILE + "'" );

      if( propFile.exists() == false )
      {
         System.out.println( "Log4Test: Properties file doesn't exist, will exit" );
         System.out.flush();
      }
      else
      {
         try
         {
            is = new FileInputStream( propFile );
            props.load( is );

            // set the appender file location
            String localhost = InetAddress.getLocalHost().getHostName();
            // String filename = redmandir + "/../logs/" + TRACE_FILE + "-" + localhost + ".log";
            String filename = "/tmp/" + TRACE_FILE + ".log"; 
            props.setProperty( "log4j.appender.testlogger.File", filename );

            //
            // Configure log4j
            //
            PropertyConfigurator.configure( props );

            trace.info("Log configuration loaded from " + propFile.getAbsolutePath());
         }
         catch( Exception x )
         {
            System.out.println( "Log4Test: Unexpected exception while loading properties, " + x + ", exiting" );
         }
      }
   }
    /** Creates new Log4Test */
    public Log4Test1() {
    }

}